package com.example.bijidemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.bijidemo.common.CustomException;
import com.example.bijidemo.entity.Category;
import com.example.bijidemo.entity.Renwu;
import com.example.bijidemo.mapper.CategoryMapper;
import com.example.bijidemo.service.CategoryService;
import com.example.bijidemo.service.RenWuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Autowired
    RenWuService renWuService;

    @Override
    public void remove(Long id) {
        //根据id查询任务
        LambdaQueryWrapper<Renwu> a=new LambdaQueryWrapper<>();
        a.eq(Renwu::getCategoryId,id);
        int count = renWuService.count(a);
        if (count>0){
            throw new CustomException("请先删除该分类中的任务");
        }

        super.removeById(id);
    }
}
